<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<script src="js/mui.js"></script>
		<script src="./utils/myRequest.js"></script>
		<script type="text/javascript">
			mui.init();
			mui.plusReady(function() {
				//获取上个页面传过来的值
				var name = plus.webview.currentWebview().name;
				var user = store.getItem();

				// plus.nativeUI.toast(name);
				var param = new Object();
				param.username = name;

				var toId = null;

				request.ajax({
					url: "/websocket/user/getUser",
					data: param,
					type: "post",
					success: function(resp) {
						console.log(typeof resp);
						console.log(resp.code == 20000);
						if (resp.code == 20000) {
							//获取ul对象
							var user1 = resp.data.user;
							document.getElementById("username").innerText = user1.username;
							document.getElementById("nickname").innerText = user1.nickname;
							document.getElementById("minImg").src = user1.minHeand;
						}
					}

				});

				

				//发送好友验证
				document.getElementById("sendFriend").addEventListener("tap", function() {
					//拼接请求对象
					var param2 = new Object();
					param2.fromId = user.id;
					param2.toName = name;
					param2.msg = document.getElementById("msg").value;
					param2.remark = document.getElementById("remark").value;
					
					console.log(JSON.stringify(param2));
					
					request.ajax({
						url: "/websocket/t-friend-apply/sendFriend",
						data: param2,
						type: "post",
						success: function(resp) {
							console.log(typeof resp);
							// console.log(resp.code == 20000);
							if (resp.code == 20002) {
								//获取ul对象
								plus.nativeUI.toast(resp.message);
							}else if(resp.code == 20003){
								plus.nativeUI.toast(resp.message);
							}else if(resp.code == 20004){
								plus.nativeUI.toast(resp.message);
							}else if(resp.code == 20000){
								plus.nativeUI.toast(resp.message);
								//回退到上一页
								mui.back();
							}else{
								plus.nativeUI.toast(resp.message);
							}
						}

					});

				});

			});
		</script>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">好友认证</h1>
		</header>

		<div style="margin-top: 50px;">
			<ul class="mui-table-view" id="ul" style="margin-top: 50px;margin-bottom: 10px;">
				<li class="mui-table-view-cell mui-media">
					<a href="javascript:;">
						<img class="mui-media-object mui-pull-left" id="minImg" src="img/tou.jpg">
						<div class="mui-media-body">
							<p id="username" class="mui-ellipsis"></p>
							<p id="nickname" class="mui-ellipsis"></p>
						</div>
					</a>
				</li>
			</ul>
			<p style="margin-left: 10px;">填写验证信息</p>
			<textarea id="msg">我是....</textarea>
			<p style="margin-left: 10px;">备注</p>
			<input id="remark" type="text" placeholder="请输入备注" style="margin-bottom: 50px;" />
			<ul class="mui-table-view" style="text-align: center;color: white;background-color: #2AC845;">
				<li class="mui-table-view-cell mui-media" id="sendFriend">
					<a href="javascript:;">
						发送
					</a>
				</li>
			</ul>
		</div>
	</body>

</html>
